package com.javasm.mingming.dynamic.controller;

import com.github.pagehelper.PageInfo;
import com.javasm.mingming.common.R;
import com.javasm.mingming.dynamic.entity.Dynamics;
import com.javasm.mingming.dynamic.service.DynamicsService;
import org.springframework.data.repository.query.Param;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;

/**
 * (Dynamics)表控制层
 *
 * @author makejava
 * @since 2025-01-06 17:31:28
 */
@RestController
@RequestMapping("/dynamics")
public class DynamicsController {
    /**
     * 服务对象
     */
    @Resource
    private DynamicsService dynamicsService;

    @GetMapping("/page")
    private R dynamicList(@RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
                          @RequestParam(value = "pageSize",defaultValue = "3") Integer pageSize){
        PageInfo<Dynamics> pageInfo = dynamicsService.getPageInfo(pageNum,pageSize);
        return R.ok(pageInfo);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public R selectOne(@PathVariable Serializable id) {
        return R.ok(this.dynamicsService.getById(id));
    }

    /**
     * 新增数据
     *
     * @param dynamics 实体对象
     * @return 新增结果
     */
    @PostMapping
    public R insert(@RequestBody Dynamics dynamics) {
        return R.ok(this.dynamicsService.save(dynamics));
    }

    /**
     * 修改数据
     *
     * @param dynamics 实体对象
     * @return 修改结果
     */
    @PutMapping
    public R update(@RequestBody Dynamics dynamics) {
        return R.ok(this.dynamicsService.updateById(dynamics));
    }

    /**
     * 删除数据
     *
     * @param idList 主键结合
     * @return 删除结果
     */
    @DeleteMapping
    public R delete(@RequestParam("idList") List<Long> idList) {
        return R.ok(this.dynamicsService.removeByIds(idList));
    }
}

